package com.bcxj.apipassenger.service;

import com.bcxj.apipassenger.remote.ServiceUserClient;
import com.bcxj.internalcommon.constant.IdentityConstant;
import com.bcxj.internalcommon.constant.TokenConstant;
import com.bcxj.internalcommon.response.ResponseResult;
import com.bcxj.internalcommon.util.JwtUtils;
import com.bcxj.internalcommon.util.RedisPrefixUtils;
import com.bcxj.internalcommon.vo.TravelUserVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service;

/**
 * ClassName: UserService
 * Package: com.bcxj.apipassenger.service
 * Description:
 *
 * @Author BCXJ
 * @Create 2025/3/5 23:47
 * @Version 1.0
 * @Since 1.0
 */
@Service
public class UserService {

    @Autowired
    private ServiceUserClient serviceUserClient;


    @Autowired
    private StringRedisTemplate redisTemplate;
    /**
     * 根据手机号获取用户的信息
     * @param phone
     * @return
     */
    public ResponseResult<TravelUserVO> getUser(String phone) {
        return serviceUserClient.getUser(phone);
    }


    /**
     * 用户退出登录
     * @param phone
     * @return
     */
    public ResponseResult out(String phone) {
        // 获取key
        String accessTokenKey = RedisPrefixUtils.generatorTokenKey(phone, IdentityConstant.USER_IDENTITY, TokenConstant.ACCESS_TOKEN);
        String refreshTokenKey = RedisPrefixUtils.generatorTokenKey(phone, IdentityConstant.USER_IDENTITY, TokenConstant.REFRESH_TOKEN);
        // 删除accessToken
        redisTemplate.delete(accessTokenKey);
        // 删除refreshToken
        redisTemplate.delete(refreshTokenKey);
        return ResponseResult.success();
    }
}
